home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / examples / accum / accpersp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  3.4 KB  |  108 lines

  1. /*
  2.  * Copyright 1993, 1995, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /*
  19.  * accpersp.c
  20.  * This file contains functions for performing jittering.
  21.  *
  22.  */
  23.  
  24. #include <GL/gl.h>
  25. #include <GL/glu.h>
  26. #include <math.h>
  27.  
  28. GLvoid accFrustum(GLdouble, GLdouble, GLdouble, GLdouble,
  29.     GLdouble, GLdouble, GLdouble, GLdouble, 
  30.     GLdouble, GLdouble, GLdouble);
  31. GLvoid accPerspective(GLdouble, GLdouble, GLdouble, GLdouble,
  32.     GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
  33.  
  34. /*    accFrustum()
  35.  *  The first 6 arguments are identical to the glFrustum() call.
  36.  *  
  37.  *  pixdx and pixdy are anti-alias jitter in pixels. 
  38.  *  Set both equal to 0.0 for no anti-alias jitter.
  39.  *
  40.  *  eyedx and eyedy are depth-of field jitter in pixels. 
  41.  *  Set both equal to 0.0 for no depth of field effects.
  42.  *
  43.  *  focus is distance from eye to plane in focus. 
  44.  *  focus must be greater than, but not equal to 0.0.
  45.  *
  46.  *  Note that accFrustum() calls glTranslatef().  You will 
  47.  *  probably want to insure that your ModelView matrix has been 
  48.  *  initialized to identity before calling accFrustum().
  49.  */
  50. void accFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top,
  51.     GLdouble near, GLdouble far, GLdouble pixdx, GLdouble pixdy, 
  52.     GLdouble eyedx, GLdouble eyedy, GLdouble focus)
  53. {
  54.     GLdouble xwsize, ywsize; 
  55.     GLdouble dx, dy;
  56.     GLint viewport[4];
  57.     
  58.     xwsize = right - left;
  59.     ywsize = top - bottom;
  60.     
  61.     glGetIntegerv (GL_VIEWPORT, viewport);
  62.     dx = -(pixdx*xwsize/(GLdouble) viewport[2] + 
  63.         eyedx*near/focus);
  64.     dy = -(pixdy*ywsize/(GLdouble) viewport[3] + 
  65.         eyedy*near/focus);
  66.     
  67.     glMatrixMode(GL_PROJECTION);
  68.     glLoadIdentity();
  69.     glFrustum (left + dx, right + dx, bottom + dy, top + dy, near, far);
  70.     glMatrixMode(GL_MODELVIEW);
  71.     glLoadIdentity();
  72.     glTranslatef (-eyedx, -eyedy, 0.0);
  73. }
  74.  
  75. /*  accPerspective()
  76.  * 
  77.  *  The first 4 arguments are identical to the gluPerspective() 
  78.  *  call. 
  79.  *
  80.  *  pixdx and pixdy are anti-alias jitter in pixels. 
  81.  *  Set both equal to 0.0 for no anti-alias jitter.
  82.  *
  83.  *  eyedx and eyedy are depth-of field jitter in pixels. 
  84.  *  Set both equal to 0.0 for no depth of field effects.
  85.  *
  86.  *  focus is distance from eye to plane in focus. 
  87.  *  focus must be greater than, but not equal to 0.0.
  88.  *
  89.  *  Note that accPerspective() calls accFrustum().
  90.  */
  91. void accPerspective(GLdouble fovy, GLdouble aspect, 
  92.     GLdouble near, GLdouble far, GLdouble pixdx, GLdouble pixdy, 
  93.     GLdouble eyedx, GLdouble eyedy, GLdouble focus)
  94. {
  95.     GLdouble fov2,left,right,bottom,top;
  96.  
  97.     fov2 = ((fovy*M_PI) / 180.0) / 2.0;
  98.  
  99.     top = near / (cos(fov2) / sin(fov2));
  100.     bottom = -top;
  101.  
  102.     right = top * aspect;
  103.     left = -right;
  104.  
  105.     accFrustum (left, right, bottom, top, near, far,
  106.     pixdx, pixdy, eyedx, eyedy, focus);
  107. }
  108.